window.addEventListener('load',function(){
    //手机号码验证
    let regphone=/^1[3|5|7|8|9]\d{9}$/;
    let phone=document.querySelector('#phone');
    regexp(phone,regphone);


    //密码验证
    let regpwd=/^[a-zA-Z]\w{5,17}$/;
    let pwd=document.querySelector('#pwd');
    regexp(pwd,regpwd);

    //确认密码
    let surepwd=document.querySelector('#surepwd');
    surepwd.onblur=function(){
        if(this.value==pwd.value){
            this.nextElementSibling.className="success";
            this.nextElementSibling.innerHTML='<i class="success_icon"></i>输入正确';
        }else{
            this.nextElementSibling.className="error";
            this.nextElementSibling.innerHTML='<i class="error_icon"></i>两次密码不一致';
        }
    }

    //验证码
    let regcode=/^\d{6}$/;
    let phoneCode=document.querySelector('#phoneCode');
    regexp2(phoneCode,regcode);

    //获取验证码
    let codeBtn=document.querySelector('.codeBtn');
    let count=10;
    codeBtn.onclick=function(){
        this.setAttribute("disabled","disabled");
        let t=setInterval(() => {
            this.innerHTML=count+"s";
            count--;
            if(count==0){
                clearInterval(t);
                this.removeAttribute("disabled"); 
                count=1
                0;
                this.innerHTML="获取验证码";
            }
        }, 1000);
    }


    //验证节点是否匹配规则
    function regexp(ele,reg){
        ele.onblur=function(){
            if(reg.test(this.value)){
                this.nextElementSibling.className="success";
                this.nextElementSibling.innerHTML='<i class="success_icon"></i>格式正确';
            }else{
                this.nextElementSibling.className="error";
                this.nextElementSibling.innerHTML='<i class="error_icon"></i>格式不正确';
            }    
        }
    }

    function regexp2(ele,reg){
        ele.onblur=function(){
            if(reg.test(this.value)){
                this.nextElementSibling.nextElementSibling.className="success";
                this.nextElementSibling.nextElementSibling.innerHTML='<i class="success_icon"></i>格式正确';
            }else{
                this.nextElementSibling.nextElementSibling.className="error";
                this.nextElementSibling.nextElementSibling.innerHTML='<i class="error_icon"></i>格式不正确';
            }    
        }
    }

  

});